//
//  SelfPublishListViewController.m
//  WuShiCity
//
//  Created by chengjie on 16/7/5.
//  Copyright © 2016年 chengjie. All rights reserved.
//

#import "SelfPublishListViewController.h"
#import "SelfPublishListTableViewCell.h"

#import "UITableView+EmptyData.h"

@interface SelfPublishListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation SelfPublishListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    [self goPublish];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - ---------设置发布按钮---------------
- (void)goPublish {
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setFrame:CGRectMake(10, 300, kScreenWidth-20, 30)];
    [btn setTitle:@"快去发布吧" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(goPublishBtn:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor redColor];
    if (self.dataSource.count == 0) {
        
        [self.view addSubview:btn];
    }else {
        
        [self.view bringSubviewToFront:self.tableView];
    }
}

- (void)goPublishBtn:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - -----------tableView的代理方法-------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [tableView showMessage:@"还没有发布任何消息" btnTitle:@"" byDataSourceCount:self.dataSource.count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    SelfPublishListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelfPublishListCell" forIndexPath:indexPath];
    return cell;
}

#pragma mark - ------laying-------
- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight/2)];
        [_tableView registerNib:[UINib nibWithNibName:@"SelfPublishListTableViewCell" bundle:nil] forCellReuseIdentifier:@"SelfPublishListCell"];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (NSMutableArray *)dataSource {
    
    if (!_dataSource) {
        
        _dataSource = [[NSMutableArray alloc] init];
    }
    return _dataSource;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
